<%--
  Created by IntelliJ IDEA.
  User: CY
  Date: 2018/1/4
  Time: 10:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
<head>
    <title>油烟在线检测</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8 ? MYOA_CHARSET : htmlspecialchars($HTML_PAGE_CHARSET))?>" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/css/street/street.css"/>
    <link rel="stylesheet" href="/css/officialDocument/officialDocument.css">
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <link rel="stylesheet" href="/lib/layer/skin/default/layer.css">
    <%--<link rel="stylesheet" type="text/css" href="/css/patrol/patrol.css"/>--%>
    <link rel="stylesheet" href="/css/base.css">
    <script src="../js/jquery/jquery-1.9.1.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layer/layer.js?20201106" type="text/javascript" charset="utf-8"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/base/tablePage.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <style>
        body{
            margin:0px;
        }
        .info{
            width:180px;
            height:28px;
            border-radius: 3px;
            margin-left:20px;
            vertical-align: middle;
        }
        button{
            background: #2f8ae3;
            margin-left: 10px;
            padding: 5px 10px;
            border-radius: 4px;
            color: #fff;
            cursor: pointer;
            font-size:14px;
        }
        #add{
            float:right;
            margin:0px 20px 8px 0px;
        }
        .table{
            width:96%;
            margin:20px auto 0px;
        }
        .tableFoot{
            margin-top:20px;
        }
        .childCheck{
            width:16px;
            vertical-align: middle;
        }
        #checkAll{
            margin-left:10px;
        }
        #outport{
            background: #cc0000;
        }
        #inportEdit{
            background: #009900;
        }
        .M-box3 .active{
            margin: 0px 3px;
            width: 29px;
            height: 29px;
            line-height: 29px;
            background: #2b7fe0;
            font-size: 12px;
            border: 1px solid #2b7fe0;
            color:#fff;
            text-align:center;
            display: inline-block;
        }
        .M-box3 a{
            margin: 0 3px;
            width: 29px;
            height: 29px;
            line-height: 29px;
            font-size: 12px;
            display: inline-block;
            text-align:center;
            background: #fff;
            border: 1px solid #ebebeb;
            color: #bdbdbd;
            text-decoration: none;
        }
        .mainBg .mainTitle{
            min-width: 750px;
        }
        .mainTitleUl .bordercolor span{
            font-size:14px;
        }
        .mainTitleUl .bordercolor label input[type=text]{
            font-size:14px;
        }
        .mainBg{
            padding-top:0px;
        }
        #grid{
            background: none!important;
        }
        #add{
            position: static!important;
            margin-bottom:10px!important;
        }
    </style>
    <link rel="stylesheet" href="/css/biaodan.css">
</head>
<body>
<div class="content" style="padding-top:35px;">
    <div class="tableList" >
        <div class="headNav" style="margin-top:18px;">
            <%--<input type="text" class="info" placeholder="企业信息">--%>
            <%--<button id="query">查询</button>--%>
            <button id="inport" style="margin-left:30px;">导入</button>
            <%--<button id="inportEdit">导入修改</button>--%>
            <button class="choose" id="add" data-type="0">新建</button>
        </div>
        <div class="table">
            <table>
                <thead>
                <tr>
                    <%--<th style="width:1%"></th>--%>
                    <th>序号</th>
                    <th>企业名称</th>
                    <th>详细地址</th>
                    <th>联系人</th>
                    <th>联系电话</th>
                    <th>设备状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody class="list">

                </tbody>
            </table>
            <%--<div class="tableFoot">--%>
            <%--<input type="checkbox" id="checkAll"  style="width:16px;vertical-align: middle">--%>
            <%--<label for="checkAll" style="font-size:14px;">全选</label>--%>
            <%--<button id="outport">导出</button>--%>
            <%--</div>--%>
            <div style="margin: 0px auto 0px;height:50px;width: 97%;" class="clearfix">
                <div id="dbgz_page" class="M-box3" style="display: none">

                </div>
            </div>
        </div>
    </div>
    <div class="mainBg" style="background: #fff;display: none">
        <form action="" id="datasave">
            <%--<input type="file"  onchange="filesTwo(this)" multiple="multiple" name="file"--%>
            <%--style="display: none"/>--%>
            <%--<input type="hidden" name="userId">--%>
            <%--<input type="hidden" name="checkId">--%>
            <div class="mainTitle">
                <ul class="mainTitleUl">
                    <li style="    padding-top: 18px;text-align: center;height: 61px;border-bottom: 1px solid #ddd"><span class="spanSize">油烟在线检测情况信息单</span> </li>
                    <li class="bordercolor clearfix">
                        <span style="border-bottom: 1px solid #fff;">企业名称</span>
                        <label style="width: 80%;">
                            <input type="text" name="enterpriseName" placeholder="请填写企业名称" style="background: #fcfcfc;    width: 92%;
    float: none;
    margin-top: 9px;">
                        </label>
                    </li>
                    <li class="bordercolor clearfix">
                        <span style="border-bottom: 1px solid #fff;">详细地址</span>
                        <label style="width: 80%;">
                            <input type="text" name="xydz" placeholder="请填写详细地址" style="background: #fcfcfc;    width: 92%;
    float: none;
    margin-top: 9px;">
                        </label>
                    </li>
                    <li class="bordercolor clearfix">
                        <span style="border-bottom: 1px solid #fff;">坐标<b style="color: red;">*</b></span>
                        <label style="width: 80%;position:relative">
                            <input type="text" name="gridLocation" style="width:92%" readonly="readonly">
                            <button type="button" class="dwbtn" style="position: absolute;width: 82px;height: 39px; background-color: #228cdc;color: #fff; right: 22px;top:9px;border-radius: 3px;cursor: pointer;">点击定位</button>
                        </label>
                    </li>
                    <li class="bordercolor clearfix">
                        <span style="border-bottom: 1px solid #fff">联系人 </span>
                        <label>
                            <input type="text" name="telname" placeholder="请填写联系人" style="margin: 9px auto 0px;float: none;">
                        </label>
                        <span>联系电话</span>
                        <label>
                            <input type="text" name="tel" placeholder="请选择联系电话" style="margin: 9px auto 0px;float: none;">
                        </label>
                    </li>
                    <li class="bordercolor clearfix">
                        <span style="border-bottom: 1px solid #fff;">设备状态</span>
                        <label style="width: 80%;">
                            <input type="text" name="menke" placeholder="请填写设备状态" style="background: #fcfcfc;    width: 92%;
    float: none;
    margin-top: 9px;">
                        </label>
                    </li>
                    <li class="bordercolor clearfix">
                        <span style="border-bottom: 1px solid #fff;height: 104px;line-height: 104px">备注</span>
                        <label style="width: 80%;height: 104px;">
                            <textarea name="bein" id="bein"  placeholder="请填写备注" style="background: #fcfcfc;font-size:14px;"></textarea>
                        </label>
                    </li>

                </ul>
                <div style="height: 60px;line-height:60px;text-align: center">
                    <a href="javascript:void (0)" class="preservation" style="
                margin-top: 25px;display: inline-block;margin-right: 10px;
                line-height: 1;font-size:18px;padding: 8px 20px;
                background: #2F8AE3;color: #fff;border-radius: 6px">保存</a>
                    <a href="javascript:void (0)" class="getBack"  style="
                margin-top: 25px;display: inline-block;
                line-height: 1;font-size:18px;padding: 8px 20px;background: #2F8AE3;color: #fff;border-radius: 6px">返回</a>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    $(document).on('click','.choose',function(){
        var type=$(this).attr('data-type');
        $('.tableList').hide();
        $('.mainBg').show();
        if(type==0){//新建
            $('.preservation').attr('data-type','0');
            $('.preservation').show();
            use();
            refresh()
            $('#datasave').attr('action','/TrashDetectionController/addtrde')
        }else if(type==1){//查看
            var id=$(this).parents('tr').attr('id')
            $('.preservation').hide();
            noUser();
            detail(id)
        }else{//修改
            var id=$(this).parents('tr').attr('id')
            $('.preservation').attr('data-type','2')
            $('.preservation').show();
            $('#datasave').attr('action','/TrashDetectionController/updatetrde?tinid='+id)
            use();
            detail(id)
        }
    })
    //    点击返回
    $('.getBack').click(function(){
        $('.tableList').show();
        $('.mainBg').hide();
    })
    //    点击坐标定位
    $('.dwbtn').click(function () {
        window.open('/street/chooseMap')
    })
    //    设置坐标
    function setZuobiao(str){
        $('input[name="gridLocation"]').val(str)
    }
    //    禁用
    function noUser(){
        $('.mainBg input[type="text"]').attr('disabled','disabled');
        $('.mainBg input[type="radio"]').attr('disabled','disabled');
        $('textarea').attr('disabled','disabled');
    }
    //    可以使用
    function use(){
        $('input[type="text"]').removeAttr('disabled');
        $('input[type="radio"]').removeAttr('disabled');
        $('textarea').removeAttr('disabled');
    }

    //    分页列表
    var ajaxPageLe={
        data:{
            page:1,//当前处于第几页
            pageSize:10,//一页显示几条
            useFlag:true,
            mid:""
            // computationNumber:null
        },
        page:function () {
            var me=this;
            $.ajax({
                url:'/TrashDetectionController/trdeSelect',
                type:'get',
                data:me.data,
                dataType:'json',
                success:function(reg){
                    var datas=reg.obj;
                    var str="";
                    for(var i=0;i<datas.length;i++){
                        str+=' <tr id="'+datas[i].tinid+'">' +
                            //                            '                    <td>' +
                            //                            '                        <input type="checkbox" class="childCheck">' +
                            //                            '                    </td>' +
                            '                    <td>'+(i+1)+'</td>' +
                            '                    <td>'+'<a href="javascript:;" class="choose" data-type="1">'+datas[i].enterpriseName+'</a>'+'</td>' +
                            '                    <td>'+datas[i].xydz+'</td>' +
                            '                    <td>'+datas[i].telname+'</td>' +
                            '                    <td>'+datas[i].tel+'</td>' +
                            '                    <td>'+datas[i].menke+'</td>' +
                            '                    <td>' +
//                            '                        <a href="javascript:;" class="choose" data-type="1">查看</a>' +
                            '                        <a href="javascript:;" class="choose" data-type="2">修改</a>' +
                            '                        <a href="javascript:;" class="del">删除</a>' +
                            '                    </td>' +
                            '                </tr>'
                    }
                    $('.list').html(str);
                    if(reg.object>10){
                        $('#dbgz_page').show();
                        me.pageTwo(reg.object,me.data.pageSize,me.data.page)
                    }else{
                        $('#dbgz_page').hide();
                    }


                }
            })

        },
        pageTwo:function (totalData, pageSize,indexs) {
            var mes=this;
            $('#dbgz_page').pagination({
                totalData: totalData,
                showData: pageSize,
                jump: true,
                coping: true,
                homePage:'',
                endPage: '',
                current:indexs||1,
                callback: function (index) {
                    mes.data.page=index.getCurrent();
                    mes.page();
                }
            });
        }
    }
    ajaxPageLe.page();
    //    点击全选
    $('#checkAll').click(function(){
        var state=$(this).prop('checked');
        if(state == true){
            $(this).prop('checked',true);
            $('.childCheck').prop('checked',true);
        }else{
            $(this).prop('checked',false);
            $('.childCheck').prop('checked',false);
        }
    })
    //    点击删除
    $('.list').on('click','.del',function(){
        var id=$(this).parents('tr').attr('id')
        layer.confirm(' 确定要删除吗', {
            btn: ['确定', '取消'], //按钮
            title: " 删除"
        },function(){
            $.ajax({
                url:'/TrashDetectionController/deletetrde',
                type:'post',
                dataType:'json',
                data:{tinid:id},
                success:function(){
                    layer.msg(' 删除成功', {icon: 6});
                    ajaxPageLe.page();
                }
            })
        }, function () {
            layer.closeAll();
        })
    })

    //    点击保存
    $('.preservation').click(function(){
        if($('input[name="enterpriseName"]').val()==""){
            $.layerMsg({content:'请填写企业名称',icon:6})
            return;
        }
        if($('input[name="xydz"]').val()==""){
            $.layerMsg({content:'请填写详细地址',icon:6})
            return;
        }
        if($('input[name="telname"]').val()==""){
            $.layerMsg({content:'请填写联系人',icon:6})
            return;
        }
        if($('input[name="tel"]').val()==""){
            $.layerMsg({content:'请填写联系电话',icon:6})
            return;
        }
        if($('input[name="gridLocation"]').val()==""){
            $.layerMsg({content:'请选取坐标',icon:6})
            return;
        }
        var type=$(this).attr('data-type');
        $('input[name="deptName"]').val($('#grid option:selected').text())
        if(type==0){//新建
            $('#datasave').ajaxSubmit({
                type:'post',
                dataType:'json',
                success:function(res){
                    if(res.flag){
                        $.layerMsg({content:'新建成功',icon:1})
                        $('.tableList').show();
                        $('.mainBg').hide();
                        ajaxPageLe.data.page=1;
                        ajaxPageLe.page();
                    }else{
                        $.layerMsg({content:'新建失败',icon:1})
                    }
                }
            })
        }else if(type==2){
            $('#datasave').ajaxSubmit({
                type:'post',
                dataType:'json',
                success:function(res){
                    if(res.flag){
                        $.layerMsg({content:'修改成功',icon:1})
                        $('.tableList').show();
                        $('.mainBg').hide();
                        ajaxPageLe.data.page=1;
                        ajaxPageLe.page();
                    }else{
                        $.layerMsg({content:'修改失败',icon:1})
                    }
                }
            })
        }
    })

    //    查看详情
    function  detail(id) {
        $.ajax({
            url:'/TrashDetectionController/trdeSelect',
            data:{tinid:id,
                page:1,//当前处于第几页
                pageSize:10,//一页显示几条
                useFlag:true},
            dataType:'json',
            type:'get',
            success:function(res){
                var data=res.obj[0];
                console.log(data);
                $('input[name="gridLocation"]').val(data.gridLocation);//灶头数
                $('input[name="enterpriseName"]').val(data.enterpriseName);//所属社区
                $('input[name="xydz"]').val(data.xydz)//垃圾桶总数
                $('input[name="telname"]').val(data.telname);//架子总数
                $('input[name="tel"]').val(data.tel);//绿桶总数
                $('input[name="menke"]').val(data.menke);//破损数量
                $('#bein').val(data.bein);//备注
            }
        })
    }

    //    ridio check
    function check(name,data){
        $(':radio[name="'+name+'"][value="'+data+'"]').prop('checked','check')

    }
    //    点击查询
    $('#query').click(function(){
        ajaxPageLe.data.unit=$('.info').val();
        ajaxPageLe.page();
    })

    //    点击导入
    $('#inport').click(function(){
        layer.open({
            type:1,
            title: ['油烟在线检测信息导入', 'background-color:#2b7fe0;color:#fff;'],
            area: ['600px', '420px'],
            btn: ['导入', '取消'],
            content:'<div>' +
            '<form class="form1" name="form1" id="uploadForm" method="post" action="/TrashDetectionController/ecoudInsert" enctype="multipart/form-data">' +
            '<table class="importTable"> ' +
            '<tr><td style="width: 100px;">下载导入模板：</td><td style="text-align: left;"><a id="model" style="cursor:pointer">油烟在线检测模板下载</a></td></tr>' +
            '<tr> <td>选择导入文件：</td> <td><input style="width: auto" type="file" name="file"/></td> </tr>' +
            '<tr>' +
            '<td>说明：</td>'+
            '<td style="text-align: left;"><p>1、请导入.xls文件或者.xlsx。</p>'+
//            '<p>2、请填写网格信息中已有网格。</p>'+
            ' </td> ' +
            '</tr>' +
            '</table>' +
            '</form>' +
            '</div>',
            success:function(){
                $('#model').click(function () {
                    window.location.href = encodeURI("/file/grid/油烟在线监测模板.xls");
                });
            },
            yes:function(obj){
                var flag = CheckForm();
                if (flag) {
                    layer.msg("正在导入中，请耐心等候", {icon: 1});
                    $.upload($('#uploadForm'), function (res) {
                        if(res.flag) {
                            layer.msg("导入成功", {icon: 1});
                        }else{
                            layer.msg("导入失败", {icon: 2});
                        }
                    });

                    location.reload()
                }
            }
        })
    })
    function CheckForm(){
        if(document.form1.file.value==""){
            layer.msg("请导入至少一条数据！",{icon:2});
            return (false);
        }
        return (true);
    }

    //    点击导出
    $('#outport').click(function(){
        if($('.childCheck:checked').length<=0){
            $.layerMsg({content:'请选择至少一条数据',icon:6})
        }else{
            var arr=[]
            $('.childCheck:checked').each(function(){
                var id=$(this).parents('tr').attr('id');
                arr.push(id)
            })
//            var str=arr.join()
//            console.log(str)
            window.location.href= '<%=basePath%>enCaterParameter/queryList?manyId='+arr+'&export=1';
        }

    })

    //    重置
    function refresh(){
        $('input[name="gridLocation"]').val('');//灶头数
        $('input[name="enterpriseName"]').val('');//所属社区
        $('input[name="xydz"]').val('')//垃圾桶总数
        $('input[name="telname"]').val('');//架子总数
        $('input[name="tel"]').val('');//绿桶总数
        $('input[name="menke"]').val('');//破损数量
        $('#bein').val('');//备注

    }


</script>
</body>
</html>
